/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src;

import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Viktor
 */
public class SouborIO {
    
    public boolean ulozit(String filename, Evidence e) {
        ObjectOutputStream vystup = null;
        if (filename.isEmpty()) {
            return false;
        }
        try {
            vystup = new ObjectOutputStream(new FileOutputStream(filename));
            vystup.writeObject(e);
            return true;
        } catch (IOException ex) {
            Logger.getLogger(e.getClass().getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                vystup.close();
            } catch (IOException ex) {
                Logger.getLogger(e.getClass().getName()).log(Level.SEVERE, null, ex);
            }
        }
        return false;
    }
    
    
      public Evidence nacist(String filename){
        ObjectInputStream input = null;


        Evidence data = null;
//        if (filename.isEmpty()) {
//            return null;
//        }

        try {

            input = new ObjectInputStream(new FileInputStream(filename));
            while (true) {
                data = (Evidence) input.readObject();
            }
        } catch (EOFException ex) {
            return data;
        } catch (ClassNotFoundException ex) {
        } catch (IOException ex) {
        } finally {
            try {
                if (input == null) {
                    return null;
                }
                input.close();
            } catch (IOException ex) {
            }
        }
        return null;
        }
}
